home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2000 July / macformat-092.iso / Dreamweaver 3 / Configuration / Behaviors / Actions / Control Shockwave or Flash.js < prev    next >
Encoding:
Text File  |  1999-12-01  |  11.3 KB  |  325 lines

  1. // Copyright 1998 Macromedia, Inc. All rights reserved.
  2.  
  3. //****************** GLOBAL VARS ***************
  4.  
  5. var helpDoc = MM.HELP_behControlShockwave;
  6.  
  7. function initGlobals() {
  8.   FLASHSTOP = "StopPlay";
  9.   DIRSTOP   = "Stop";  //default
  10.   CMDARRAY  = new Array("Play",DIRSTOP,"Rewind","GotoFrame");
  11.  
  12.   //use to check EMBEDs for Shockwave
  13.   FLASHSUFFIX  = new Array(".swf",".spl");
  14.   DIRSUFFIX    = new Array(".dir",".dcr");
  15.  
  16.   //use to check OBJECTs for Shockwave
  17.   FLASHCLASSID = "CLSID:D27CDB6E-AE6D-11CF-96B8-444553540000"; //must be all caps
  18.   DIRCLASSID   = "CLSID:166B1BCA-3F9C-11CF-8075-444553540000"; //must be all caps
  19. }
  20.  
  21. var FLASHSTOP;
  22. var DIRSTOP;
  23. var CMDARRAY;
  24. var FLASHSUFFIX;
  25. var DIRSUFFIX;
  26. var FLASHCLASSID;
  27. var DIRCLASSID;
  28.  
  29. //******************* BEHAVIOR FUNCTION **********************
  30.  
  31. //Causes a Shockwave object to play, stop, rewind, or go to a frame.
  32. //Accepts the following arguments:
  33. //  objStr   - name of shockwave object (full objRefs ok too)
  34. //  x        - not used (here for backward compatibility)
  35. //  cmdName  - method to invoke: Play(), Rewind(), GotoFrame(frameNum),
  36. //             StopPlay() for a Flash Movie, Stop() for Director
  37. //  frameNum - (optional) frame number, only used with GotoFrame method
  38. //
  39. //Tries to find the object, which only succeeds if the plugin is there.
  40. //Evals the concatenated pieces to call the method, for ex: document.myShock.Play()
  41.  
  42. function MM_controlShockwave(objStr,x,cmdName,frameNum) { //v3.0
  43.   var obj=MM_findObj(objStr);
  44.   if (obj) eval('obj.'+cmdName+'('+((cmdName=='GotoFrame')?frameNum:'')+')');
  45. }
  46.  
  47. document.VERSION_MM_controlShockwave = 3.0; //define latest version number for behavior inspector
  48.  
  49. //******************* API **********************
  50.  
  51.  
  52. //Checks for the existence of Shockwave movie.
  53. //If none exist, returns false so this Action is grayed out.
  54.  
  55. function canAcceptBehavior(){
  56.   if (!FLASHSUFFIX) initGlobals();
  57.   var i,j,theTag,swSrc,classId;
  58.   var tagArray = new Array;
  59.   var refArray = new Array;
  60.  
  61.   //Find all EMBED calls that contain Shockwave objects in SRC
  62.   tagArray = getAllObjectTags("embed");
  63.   refArray = getAllObjectRefs("NS 4.0","embed");
  64.   for (i in tagArray) {  //with each EMBED tag
  65.     theTag = tagArray[i];
  66.     swSrc = unescQuotes(getParam(theTag,"src"));  //get the SRC value
  67.     for (j=0; j<FLASHSUFFIX.length; j++) if (swSrc.indexOf(FLASHSUFFIX[j])>0) return true;
  68.     for (j=0; j<DIRSUFFIX.length;   j++) if (swSrc.indexOf(DIRSUFFIX[j])>0) return true;
  69.   }
  70.  
  71.   //Find all OBJECT calls that contain Shockwave objects in ClassID
  72.   //Add each unique name to the menu
  73.   tagArray = getAllObjectTags("object");
  74.   refArray = getAllObjectRefs("NS 4.0","object");
  75.   for (i in tagArray) {
  76.     theTag = tagArray[i];
  77.     classId = unescQuotes(getParam(theTag,"classid"));
  78.     if (classId) {
  79.       if (classId.toUpperCase().indexOf(FLASHCLASSID) == 0) return true;
  80.       if (classId.toUpperCase().indexOf(DIRCLASSID)   == 0) return true;
  81.     }
  82.   }
  83.   return false;  //if none of the tests above returned "true"
  84. }
  85.  
  86.  
  87.  
  88. //Returns a Javascript function to be inserted in HTML head with script tags.
  89.  
  90. function behaviorFunction() {
  91.   return "MM_findObj,MM_controlShockwave";
  92. }
  93.  
  94.  
  95.  
  96. //Returns fn call to insert in HTML tag <TAG... onEvent='thisFn(arg)'>
  97. //Calls escQuotes to find embedded quotes and precede them with \
  98.  
  99. function applyBehavior(uniqueName) {
  100.   var menuIndex,swObjNS,swObjIE,theRadio,i;
  101.   var cmdName="";
  102.   var theFrame="";
  103.  
  104.   //get shockwaveObject ID
  105.   menuIndex = document.theForm.menu.selectedIndex;
  106.   swObjNS = document.MM_NS_REFS[menuIndex];
  107.   swObjIE = document.MM_IE_REFS[menuIndex];
  108.   if (swObjNS.indexOf(REF_CANNOT)==0) {
  109.     swObjNS = "";
  110.     alert(MSG_NoNSRef)
  111.   }
  112.   if (swObjIE.indexOf(REF_CANNOT)==0) {
  113.     swObjIE = "";
  114.     alert(MSG_NoIERef);
  115.   }
  116.  
  117.   //get selected command from radio buttons
  118.   for (i=0; i<document.theForm.theCmd.length; i++) {
  119.     theRadio = document.theForm.theCmd[i];
  120.     if (theRadio.checked) {
  121.       cmdName = CMDARRAY[i];
  122.       if (cmdName == "GotoFrame") {  //get frame if GotoFrame
  123.         theFrame = document.theForm.frameNum.value;
  124.         if (theFrame != ''+parseInt(theFrame))
  125.           return MSG_InvalidFrameNum;
  126.         else if (parseInt(theFrame) < 0)
  127.           return MSG_NegFrameNum;
  128.       }
  129.       else if (cmdName == DIRSTOP) {  //Ensure it's correct stop cmd for Director/Flash
  130.         cmdName = (document.MM_shockwaveTypelist[menuIndex] == "FLASH")? FLASHSTOP : DIRSTOP;
  131.       }
  132.       break;
  133.     }
  134.   }
  135.  
  136.   if (swObjNS.indexOf(REF_UNNAMED) == 0)  //if unnamed reference
  137.     return MSG_UnnamedObj;
  138.  
  139.   if (swObjNS) enableFlashScripting( swObjNS );
  140.  
  141.   if (swObjNS && cmdName) {
  142.     swObjNS = getNameFromRef(swObjNS);
  143.     updateBehaviorFns("MM_findObj","MM_controlShockwave");
  144.     return "MM_controlShockwave('"+swObjNS+"','','"+cmdName+((theFrame)?"','"+theFrame:"")+"')";
  145.   } else {
  146.     return MSG_NoSelection;
  147.   }
  148. }
  149.  
  150.  
  151. //Returns a dummy function call to inform Dreamweaver the type of certain behavior
  152. //call arguments. This information is used by DW to fixup behavior args when the
  153. //document is moved or changed.
  154. //
  155. //It is passed an actual function call string generated by applyBehavior(), which
  156. //may have a variable list of arguments, and this should return a matching mask.
  157. //
  158. //The return values are:
  159. //  URL     : argument could be a file path, which DW will update during Save As...
  160. //  NS4.0ref: arg is an object ref that may be changed by Convert Tables to Layers
  161. //  IE4.0ref: arg is an object ref that may be changed by Convert Tables to Layers
  162. //  other...: argument is ignored
  163.  
  164. function identifyBehaviorArguments(fnCallStr) {
  165.   var argArray, retVal="", fullObjRef;;
  166.  
  167.   argArray = extractArgs(fnCallStr);
  168.   fullObjRef = (argArray[1].indexOf(".")!=-1);
  169.   if (argArray.length == 4) {
  170.     retVal = (fullObjRef)?"NS4.0ref,IE4.0ref,other" : "objName,other,other";
  171.   } else if (argArray.length == 5) {
  172.     retVal = (fullObjRef)?"NS4.0ref,IE4.0ref,other,other" : "objName,other,other,other";
  173.   }
  174.   return retVal;
  175. }
  176.  
  177.  
  178.  
  179. //Passed the function call above, takes prior arguments and reloads the UI.
  180. //Removes any escape characters "\"
  181.  
  182. function inspectBehavior(argStr){
  183.   var swName,menuLength,i;
  184.   var argArray = new Array;
  185.   var found = false;
  186.  
  187.   argArray = extractArgs(argStr); //get args
  188.   if (argArray.length > 3) {  //should be 4 or 5 args (0 and 2 ignored)
  189.  
  190.     //select shockwaveId
  191.     swName = unescQuotes(argArray[1]);
  192.     menuLength = document.MM_NS_REFS.length;
  193.     for (i=0; i<menuLength; i++) { //search menu for matching shockwave name
  194.       if (swName == document.MM_NS_REFS[i] || swName == getNameFromRef(document.MM_NS_REFS[i])) { //if found
  195.         document.theForm.menu.selectedIndex = i;  //make it selected
  196.         found = true;
  197.         break;
  198.       }
  199.     }
  200.     if (!found) alert(errMsg(MSG_ShockwaveNotFound,swName));
  201.  
  202.     //select appropriate radio button
  203.     cmdName = argArray[3];
  204.     if (cmdName == FLASHSTOP) cmdName = DIRSTOP;
  205.     for (i=0; i<document.theForm.theCmd.length; i++)
  206.       document.theForm.theCmd[i].checked = (cmdName == CMDARRAY[i]);
  207.  
  208.     //stuff frame num if there
  209.     if (argArray.length > 4) {
  210.       document.theForm.frameNum.value = argArray[4];
  211.     }
  212.   }
  213. }
  214.  
  215.  
  216.  
  217. //***************** LOCAL FUNCTIONS  ******************
  218.  
  219.  
  220. //Searches for all Shockwave EMBEDs and OBJECTs on the page,
  221. //eliminating duplicates, and adding them to the menu.
  222.  
  223. function initializeUI(){
  224.   initGlobals();
  225.   var i,j,k,theTag,swSrc,swName,classId,notInMenu;
  226.   var tagArray = new Array;
  227.   var NSrefArray = new Array;
  228.   var IErefArray = new Array;
  229.   var paramArray = new Array;
  230.   var mIndex=0;
  231.   var isFlash, isDir;
  232.   var shockwaveTypelist = new Array;
  233.   var IErefs = new Array;
  234.   var NSrefs = new Array;
  235.   var niceNameArray = new Array;
  236.  
  237.   //Find all EMBED calls that contain ShockWave objects in SRC
  238.   //Add each unique name to the menu list
  239.   tagArray = getAllObjectTags("embed"); //get the tags to search
  240.   NSrefArray = getAllObjectRefs("NS 4.0","embed"); //get parallel EMBED obj refs
  241.   IErefArray = getAllObjectRefs("IE 4.0","embed");
  242.   for (i in tagArray) {  //with each EMBED tag
  243.     theTag = tagArray[i];
  244.     isFlash = false;  isDir = false;  //search for Flash or Director suffixes
  245.     swSrc = unescQuotes(getParam(theTag,"src"));  //get the SRC value
  246.     if (swSrc) {
  247.       for (j=0; j<FLASHSUFFIX.length; j++) if (swSrc.indexOf(FLASHSUFFIX[j])>-1) isFlash=true;
  248.       for (j=0; j<DIRSUFFIX.length;   j++) if (swSrc.indexOf(DIRSUFFIX[j])  >-1) isDir  =true;
  249.       if (isFlash || isDir) {  //if found Flash or Director file suffix
  250.         swName = IErefArray[i];
  251.         if (swName.indexOf(REF_CANNOT)==0) swName=NSrefArray[i]; //if invalid IE ref, use NS ref
  252.         if (swName) {
  253.           IErefs[mIndex] = IErefArray[i];   //store IE ref into parallel array
  254.           NSrefs[mIndex] = NSrefArray[i];   //store NS ref into parallel array
  255.           shockwaveTypelist[mIndex] = (isFlash)?"FLASH":"DIR";
  256.           niceNameArray[mIndex++] = swName;
  257.         }
  258.       }
  259.     }
  260.   }
  261.  
  262.   //Find all OBJECT calls that contain ShockWave classId
  263.   //Add each unique name to the menu
  264.   tagArray = getAllObjectTags("object");
  265.   NSrefArray = getAllObjectRefs("NS 4.0","object");
  266.   IErefArray = getAllObjectRefs("IE 4.0","object");
  267.   for (i in tagArray) {
  268.     theTag = tagArray[i];
  269.     isFlash = false;  isDir = false;  //search for Flash or Director suffixes
  270.     classId = unescQuotes(getParam(theTag,"classid"));
  271.     if (classId) {
  272.       if (classId.toUpperCase().indexOf(FLASHCLASSID) == 0) isFlash = true;
  273.       if (classId.toUpperCase().indexOf(DIRCLASSID)   == 0) isDir   = true;
  274.       if (isFlash || isDir) {
  275.         swName = IErefArray[i];
  276.         if (swName.indexOf(REF_CANNOT)==0) swName=NSrefArray[i]; //if invalid IE ref, use NS ref
  277.         if (swName) {
  278.           notInMenu = true;
  279.           for (k in niceNameArray) { //check if already in menu list
  280.             if (swName == niceNameArray[k]) { //if already in menu list
  281.               notInMenu=false;        //set flag
  282.               break;
  283.             }
  284.           }
  285.           if (notInMenu) {
  286.             IErefs[mIndex] = IErefArray[i];   //store IE ref into parallel array
  287.             NSrefs[mIndex] = NSrefArray[i];   //store NS ref into parallel array
  288.             shockwaveTypelist[mIndex] = (isFlash)?"FLASH":"DIR";
  289.             niceNameArray[mIndex++] = swName;
  290.           }
  291.         }
  292.       }
  293.     }
  294.   }
  295.   niceNameArray = niceNames(niceNameArray,TYPE_Shockwave); //convert list to nice names
  296.   for (i=0; i<niceNameArray.length; i++) { //write to SELECT
  297.     document.theForm.menu.options[i]=new Option(niceNameArray[i]); //load menu
  298.   }
  299.  
  300.   document.MM_IE_REFS = IErefs; //store parallel IE refs
  301.   document.MM_NS_REFS = NSrefs; //store parallel NS refs
  302.   document.MM_shockwaveTypelist = shockwaveTypelist;  //store types of each flash item
  303.   document.theForm.menu.selectedIndex = 0;
  304. }
  305.  
  306. // enableFlashScripting()
  307. //
  308. // As of Flash 3, the swliveconnect attribute must be enabled
  309. // on the Flash object in order to use it's scripting interface
  310. // in Netscape.  The option tells Netscape to preload Live
  311. // Connect and the appropriate underlying Java classes.
  312. //
  313. function enableFlashScripting( nsObjRef )
  314. {
  315.    var userDoc = dreamweaver.getDocumentDOM( "document" );
  316.    var tagArr  = userDoc.getElementsByTagName( "embed" );
  317.  
  318.    tagArr = tagArr.concat( userDoc.getElementsByTagName( "object" ) );
  319.    for( var i = 0; i < tagArr.length; i++ ) {
  320.       if ( nsObjRef == dreamweaver.getElementRef( "NS 4.0", tagArr[i] ) ) {
  321.          tagArr[i].setAttribute( "swliveconnect", true );
  322.          return;
  323.    } }
  324. }
  325.